<?php
$pcity="rabat";
if (getParameter("city")) $pcity=getParameter("city");
$cityId=getObjByKey("portal_cities","id","lib_lt",$pcity);
$city=R::load('portal_cities',$cityId);
//R::debug(true);
$d = new DateTime();
$meteo = R::findOne('meteo_day',"cityId=? and day = ? ",array($cityId,$d->format("Y-m-d")));
if ($meteo==null)
{
	ShowError("Informations météo non disponibles.");
	
}
else {
$cityDayId=$meteo->id;


$meteo_time = R::findOne('meteo_time_details',"cityDayId=? and time <= ? Order By time desc",array($cityDayId,$d->format("H:i")));



$date=$d->format("l d M Y");


$lever=substr($meteo->lever, 0,5);
$coucher=substr($meteo->coucher, 0,5);

?>


<table>
<tr valign="top">
    <td colspan="2">
    
    
    
    <div class="switcher_form_chercher_ville">
			
			<form action="" method="GET">
				<label>Je veux voir la météo de</label>
				<select id="select_ville" name="select_ville" onchange="window.location.href=this.options[this.selectedIndex].value" >
				
				<?php

				$SQL="SELECT * FROM portal_cities where countryId=1";
				$rs=ew_LoadRecordset($SQL);
				
				while (!$rs->EOF())
				{
					$selected="";
					if ($rs->fields["id"]==$cityId) $selected="selected";
					
					?>
						<option <?=$selected?> value="/meteo/<?=strtolower($rs->fields["lib_lt"])?>.html"><?=$rs->fields["lib_lt"]?></option> 
					
					<?php 
					$rs->MoveNext();
				}
				


?>
								
				 
				</select>
				<span class="customStyleSelectBox" style="display: inline-block;"><span class="customStyleSelectBoxInner" style="width: 240px; display: inline-block;"><?=$pcity?></span></span>
			</form>  
		</div>
    
    </td>

  </tr>

  
  <tr valign="top">
    <td colspan="2">
    
    
    
    
    
    <div id="resulta-weather-ville"> 
			<div class="resulta-weather-ville-left"> 
				<div class="weathericon-big weathericon116">
				</div>
				<p align="left"><font face="sans-serif" size="4"> Aujourd'hui Détail météo </font><font face="sans-serif" size="5"><b><?=$pcity?></b></font></p>
			</div> 
			<div class="resulta-weather-ville-right"> 
				<label class="observation_c"><?=$meteo_time->temperature?>°</label>
				<label class="observation_c_r"><?=$meteo_time->temperatureressentie?>°</label>
				<label class="observation_date"><?=$date?></label>
				
				<ul class="current_condition">
					<li class="precipitations"><label><?=$meteo_time->precipitations?> mm</label></li>
					<li class="heure-observation first"><label><?php echo formatDate($meteo_time->heureobservation, "H:i:s", "H:i"); ?> PM</label></li>
					<li class="vitesse-du-vent"><label><?=$meteo_time->vitessevent?> Km/h</label></li>
					<li class="couveture-nuageuse first"><label><?=$meteo_time->couverturenuage?> %</label></li>										
					<li class="direction-du-vent"><label class="direction-vent-<?=$meteo_time->directionvent?>"></label></li>					
					<li class="pression-atmospherique first"><label><?=$meteo_time->pression?> hPa</label></li>										
					<li class="lever-du-soleil"><label><?=$lever?> AM</label></li>
					<li class="coucher-du-soleil first"><label><?=$coucher?> PM</label></li>
				</ul>
				
			</div>  
				
			<ul class="partisipations_hours"> 
				 
				 			<?php

				$SQL="SELECT * FROM meteo_time_details where cityDayId=$cityDayId";
				$rs=ew_LoadRecordset($SQL);
				
				$lever=str_ireplace($lever,":","");
				$coucher=str_ireplace($coucher,":","");
				
				while (!$rs->EOF())
				{
					$time=substr($rs->fields["time"], 0,5);
					$temp="jour";
					$heure=str_ireplace($time,":","");
					
					
				
					
				
					echo $heure;
					echo $lever;
					if ($heure<$lever) $temp="nuit";
					if ($heure>$coucher) $temp="nuit";
					
					$cssobject = R::load('meteo_etats',$rs->fields["etatId"]);
					$css=$cssobject->css;
					?>
					
						
							<li>
						<label class="time-small"><?=$time?></label>	
						<label class="weathericon-small-small-heur-<?=$temp?> weathericon-small-<?=$css?>"></label>
						<label class="observation_c-small"><?=$rs->fields["temperature"]?>°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span><?=$rs->fields["precipitations"]?>							</li>
							<li class="windspeedKmph-0">
								<span></span><?=$rs->fields["vitessevent"]?>							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-<?=$rs->fields["directionvent"]?>"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span><?=$rs->fields["couverturenuage"]?>							</li>
							<li class="pressure">
							 <span></span><?=$rs->fields["pression"]?> 
							</li> 
						</ul>  	 
					</li> 
					
					
					<?php 
					$rs->MoveNext();
				}
				


?>
		
				 
				
					
					
					<!-- 
				 
					<li>
						<label class="time-small">3:00</label>	
						<label class="weathericon-small-small-heur-nuit weathericon-small-113"></label>
						<label class="observation_c-small">21°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-0">
								<span></span>2-3							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-NW"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>3							</li>
							<li class="pressure">
							 <span></span>1017 
							</li> 
						</ul>  	 
					</li> 
				 
					<li>
						<label class="time-small">6:00</label>	
						<label class="weathericon-small-small-heur-jour weathericon-small-113"></label>
						<label class="observation_c-small">20°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-0">
								<span></span>5-9							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-N"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>4							</li>
							<li class="pressure">
							 <span></span>1017 
							</li> 
						</ul>  	 
					</li> 
				 
					<li>
						<label class="time-small">9:00</label>	
						<label class="weathericon-small-small-heur-jour weathericon-small-113"></label>
						<label class="observation_c-small">26°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-0">
								<span></span>3-4							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-N"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>24							</li>
							<li class="pressure">
							 <span></span>1018 
							</li> 
						</ul>  	 
					</li> 
				 
					<li>
						<label class="time-small">12:00</label>	
						<label class="weathericon-small-small-heur-jour weathericon-small-113"></label>
						<label class="observation_c-small">29°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-0">
								<span></span>8-9							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-NNW"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>24							</li>
							<li class="pressure">
							 <span></span>1017 
							</li> 
						</ul>  	 
					</li> 
				 
					<li>
						<label class="time-small">15:00</label>	
						<label class="weathericon-small-small-heur-jour weathericon-small-113"></label>
						<label class="observation_c-small">26°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-20">
								<span></span>20-23							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-N"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>24							</li>
							<li class="pressure">
							 <span></span>1016 
							</li> 
						</ul>  	 
					</li> 
				 
					<li>
						<label class="time-small">18:00</label>	
						<label class="weathericon-small-small-heur-jour weathericon-small-113"></label>
						<label class="observation_c-small">21°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-30">
								<span></span>20-30							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-NNE"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>23							</li>
							<li class="pressure">
							 <span></span>1017 
							</li> 
						</ul>  	 
					</li> 
				 
					<li>
						<label class="time-small">21:00</label>	
						<label class="weathericon-small-small-heur-nuit weathericon-small-113"></label>
						<label class="observation_c-small">21°</label>
						<ul class="previsiondecjour-total-bottomaccueil">
							<li class="precipmm-0">
								<span></span>0.0							</li>
							<li class="windspeedKmph-0">
								<span></span>11-15							</li>
							<li class="winddir16Point">
								<span></span><label class="direction-vent-small-ENE"></label>
							</li>
							
							<li class="cloudcover-0">
								<span></span>24							</li>
							<li class="pressure">
							 <span></span>1018 
							</li> 
						</ul>  	 
					</li>  -->
							</ul>
			
		

				<a href="/previsions/<?=$pcity?>.html" class="prevision10jours">meteo <?=$pcity?></a>
		
		
		</div>
    
    
    
    </td>

  </tr>
 
  
  
</table>

  
  <?php } ?>